package com.cskaoyan.service.system;

import com.cskaoyan.bean.MallLog;
import com.cskaoyan.bean.MallLogExample;
import com.cskaoyan.mapper.MallLogMapper;
import com.cskaoyan.model.bo.PageBo;
import com.cskaoyan.model.vo.PageListVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: project-market
 * @description:
 * @author: Weiwei Liu
 * @create: 2021-11-30 17:30
 **/
@Service
public class LogServiceImpl implements LogService {

    @Autowired
    MallLogMapper mapper;

    @Override
    public PageListVo list(PageBo pageBo, String name) {


        PageHelper.startPage(pageBo.getPage(), pageBo.getLimit());

        MallLogExample example = new MallLogExample();

        example.createCriteria().andAdminLike(name);

        // 设置分页信息
        example.setOrderByClause(pageBo.getSort() + " " + pageBo.getOrder());


        List<MallLog> list = mapper.selectByExample(example);

        //通过分页信息拿到分页数据
        //PageInfo的有参构造方法，放入的***查询结果***
        PageInfo info = new PageInfo(list);

        PageListVo vo = new PageListVo();

        vo.setTotal(info.getTotal());
        vo.setLimit(pageBo.getLimit());
        vo.setPage(info.getPageSize());
        vo.setPages(info.getPages());
        vo.setList(info.getList());

        return vo;


    }

    @Override
    public boolean create(MallLog mallLog) {

        int i = mapper.insert(mallLog);

        return i == 1;

    }
}
